package com.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.StrutsStatics;

import com.action.admin.user.LoginAction;
import com.entity.Employee;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.ValueStack;

import java.util.Date;

/**
 * 验证是否登陆，没有登陆则会到登陆页面
 * 拦截器
 * @author 
 */
public class LoginInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = -5055245287894351115L;
	public String intercept(ActionInvocation invocation) throws Exception {
		
		HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(StrutsStatics.HTTP_REQUEST);
		HttpSession session = request.getSession();  
//		判断是否为index的action类
//        Action action = (Action)invocation.getAction();
//        if (action instanceof LoginAction) {   
//        	return invocation.invoke();   
//        }   
//        Employee emp = (Employee) session.getAttribute("userinfo"); 
//		if(emp == null){
//			 ValueStack stack = invocation.getStack();  
//			 stack.set("flag", 1);  
//			System.out.println("=======拦截======="+new Date().toLocaleString());
//			return "login2";
//		}else
			return invocation.invoke();
	}
}